﻿using System;
using System.Collections.Generic;
using SharpSqlAnalyzer.pp.processor.type.comm;
using SharpSqlAnalyzer.pp.utils;
using SharpSqlAnalyzer.stmt;

namespace SharpSqlAnalyzer.pp.processor.type.merge
{
	// Token: 0x0200023B RID: 571
	public class MergeKeyWordAlignProcessor : AbstractKeyWordAlignProcessor
	{
		// Token: 0x060012E8 RID: 4840 RVA: 0x0031B7B4 File Offset: 0x003199B4
		protected internal override IList<TSourceToken[]> getTSourceToken<E>(E arg)
		{
			TMergeSqlStatement tmergeSqlStatement = arg as TMergeSqlStatement;
			IList<TSourceToken[]> list = new List<TSourceToken[]>();
			TSourceToken mergeToken = this.getMergeToken(tmergeSqlStatement);
			if (mergeToken != null)
			{
				list.Add(new TSourceToken[]
				{
					mergeToken
				});
				TSourceToken tsourceToken = SourceTokenSearcher.forwardSearch(mergeToken, 3, "into");
				if (tsourceToken != null)
				{
					list.Add(new TSourceToken[]
					{
						tsourceToken
					});
				}
			}
			if (tmergeSqlStatement.UsingTable != null)
			{
				TSourceToken tsourceToken2 = SourceTokenSearcher.backforwardSearch(tmergeSqlStatement.UsingTable.startToken, 5, "using");
				list.Add(new TSourceToken[]
				{
					tsourceToken2
				});
			}
			return list;
		}

		// Token: 0x060012E9 RID: 4841 RVA: 0x0031B840 File Offset: 0x00319A40
		private TSourceToken getMergeToken(TMergeSqlStatement node)
		{
			TSourceTokenList container = node.startToken.container;
			for (int i = 0; i < container.size(); i++)
			{
				TSourceToken tsourceToken = container.get(i);
				if (tsourceToken.ToString().Equals("merge", StringComparison.CurrentCultureIgnoreCase))
				{
					return tsourceToken;
				}
			}
			return null;
		}
	}
}
